package com.ayoka.adapter;

import com.ayoka.Constant;
import com.ayoka.R;
import com.ayoka.bean.CourseBean;
import com.jcp.baselibrary.brvah.BaseQuickAdapter;
import com.jcp.baselibrary.brvah.BaseViewHolder;
import com.jcp.baselibrary.utils.UIUtils;

import java.util.List;

/**
 * Created by jinchunping on 2018/4/11.
 */

public class CoursePackageCourseStatusAdapter extends BaseQuickAdapter<CourseBean, BaseViewHolder> {

    public CoursePackageCourseStatusAdapter(List<CourseBean> data) {
        super(R.layout.item_course_package_course_status, data);
    }

    @Override
    protected void convert(final BaseViewHolder holder, CourseBean item) {
        holder.setText(R.id.tv_day, "Day" + item.OrderNum)
                .setText(R.id.tv_course_status, "课程")
                .setText(R.id.tv_training_status, "冥想")
                .addOnClickListener(R.id.tv_course_status)
                .addOnClickListener(R.id.tv_training_status);
        if (item.IsAvailabe == 0) {
            holder.setBackgroundRes(R.id.tv_course_status, R.drawable.selector_graye_to_gray6_bg_5corner)
                    .setBackgroundRes(R.id.tv_training_status, R.drawable.selector_graye_to_gray6_bg_5corner);
            holder.setTextColor(R.id.tv_day, UIUtils.getColor(R.color.black_10))
                    .setSelected(R.id.tv_course_status, false)
                    .setSelected(R.id.tv_training_status, false);

            holder.setBackgroundColor(R.id.line_left, UIUtils.getColor(R.color.gray_e))
                    .setBackgroundRes(R.id.view_point_small, R.drawable.dot_graye)
                    .setVisible(R.id.view_point_big, false)
                    .setBackgroundColor(R.id.line_right, UIUtils.getColor(R.color.gray_e));
        } else {
            if (item.CourseCompletedStatus == Constant.CourseCompletedStatus.DISABLE) {
                holder.setBackgroundRes(R.id.tv_course_status, R.drawable.selector_graye_to_gray6_bg_5corner)
                        .setBackgroundRes(R.id.tv_training_status, R.drawable.selector_graye_to_gray6_bg_5corner);
                holder.setTextColor(R.id.tv_day, UIUtils.getColor(R.color.black_10))
                        .setSelected(R.id.tv_course_status, false)
                        .setSelected(R.id.tv_training_status, false);

                holder.setBackgroundColor(R.id.line_left, UIUtils.getColor(R.color.gray_e))
                        .setBackgroundRes(R.id.view_point_small, R.drawable.dot_graye)
                        .setVisible(R.id.view_point_big, false)
                        .setBackgroundColor(R.id.line_right, UIUtils.getColor(R.color.gray_e));
            } else if (item.CourseCompletedStatus == Constant.CourseCompletedStatus.PROCRESSING) {
                holder.setBackgroundRes(R.id.tv_course_status, R.drawable.selector_orange_bg_5corner)
                        .setBackgroundRes(R.id.tv_training_status, R.drawable.selector_graye_to_gray6_bg_5corner);
                holder.setTextColor(R.id.tv_day, UIUtils.getColor(R.color.orange_lighter))
                        .setSelected(R.id.tv_course_status, true)
                        .setSelected(R.id.tv_training_status, true);

                holder.setBackgroundColor(R.id.line_left, UIUtils.getColor(R.color.orange_lighter))
                        .setBackgroundRes(R.id.view_point_small, R.drawable.dot_orange)
                        .setVisible(R.id.view_point_big, true)
                        .setBackgroundColor(R.id.line_right, UIUtils.getColor(R.color.gray_e));
            } else if (item.CourseCompletedStatus == Constant.CourseCompletedStatus.COURSE_FINISHED) {
                holder.setBackgroundRes(R.id.tv_course_status, R.drawable.selector_white_bg_orange_1xborder_5corner)
                        .setBackgroundRes(R.id.tv_training_status, R.drawable.selector_orange_bg_5corner);
                holder.setTextColor(R.id.tv_day, UIUtils.getColor(R.color.orange_lighter))
                        .setSelected(R.id.tv_course_status, true)
                        .setSelected(R.id.tv_training_status, true);

                holder.setBackgroundColor(R.id.line_left, UIUtils.getColor(R.color.orange_lighter))
                        .setBackgroundRes(R.id.view_point_small, R.drawable.dot_orange)
                        .setVisible(R.id.view_point_big, false)
                        .setBackgroundColor(R.id.line_right, UIUtils.getColor(R.color.gray_e));
            } else if (item.CourseCompletedStatus == Constant.CourseCompletedStatus.COURSE_COMPLETED) {
                holder.setBackgroundRes(R.id.tv_course_status, R.drawable.selector_white_bg_orange_1xborder_5corner)
                        .setBackgroundRes(R.id.tv_training_status, R.drawable.selector_white_bg_orange_1xborder_5corner);
                holder.setTextColor(R.id.tv_day, UIUtils.getColor(R.color.black_10))
                        .setSelected(R.id.tv_course_status, true)
                        .setSelected(R.id.tv_training_status, true);

                holder.setBackgroundColor(R.id.line_left, UIUtils.getColor(R.color.orange_lighter))
                        .setBackgroundRes(R.id.view_point_small, R.drawable.dot_orange)
                        .setVisible(R.id.view_point_big, false)
                        .setBackgroundColor(R.id.line_right, UIUtils.getColor(R.color.orange_lighter));
            }
        }
        boolean isFirst = (holder.getLayoutPosition() - getHeaderLayoutCount()) == 0;
        boolean isBottom = holder.getLayoutPosition() == (getItemCount() - 1);
        holder.setVisible(R.id.line_left, !isFirst)
                .setVisible(R.id.line_right, !isBottom);
    }
}
